$NG.AllReady(function (
	page,
	{ useValuesChange, useDataIndexChange, useUpdateRows, useUpdateRow }
) {
	const mstform = $NG.getCmpApi("p_form_return_track_m");
	const dgrid1 = $NG.getCmpApi("p_form_return_track_d");
	useDataIndexChange(({ args }) => {
		//
		const data = args[0];
		getPtInfoByPhid(data.phid_pc, (datas) => {
			data.u_devision = datas.division_phid;
			data.u_devision_EXName = datas.division_name;

			data.u_regional_center = datas.regional_center_phid;
			data.u_regional_center_EXName = datas.regional_center_name;

			data.u_cpx = datas.midwife_phid;
			data.u_cpx_EXName = datas.midwife_name;

			data.u_xs = datas.user_sqgw_phid;
			data.u_xs_EXName = datas.user_sqgw_name;

			data.u_hkfzr = datas.project_manager_phid;
			data.u_hkfzr_EXName = datas.project_manager_name;
			dgrid1.refreshView();
		});
	}, "phid_pc");
	useValuesChange(() => {
		getPtInfoByDivision();
	}, "p_form_return_track_m.u_org");
	// 获取项目信息
	function getPtInfoByPhid(phid, fun) {
		if (phid) {
			$NG.execServer("getPtInfoByPhid", { phid }, function (res) {
				const datas = JSON.parse(res.data)[0].extendObjects;
				console.log(datas);
				fun(datas);
			});
		}
	}

	//根据事业部获取所有项目
	getPtInfoByDivision();
	function getPtInfoByDivision() {
		if (!mstform.getItem("u_org").getValue()||page.oType!=='add') return;
		$NG.execServer(
			"getPtInfoByDivision",
			{ phid: mstform.getItem("u_org").getValue() },
			(res) => {
				console.log(
					`所有项目获取`,
					res,
					mstform.getItem("u_org").getValue()
				);
				if (res.count == 0) return;
				const _data = JSON.parse(res.data);
				const _arr = [];
				_data.forEach((items) => {
					const datas = items.extendObjects;
					_arr.push({
						u_devision: datas.division_phid,
						u_devision_EXName: datas.division_name,
						u_regional_center: datas.regional_center_phid,
						u_regional_center_EXName: datas.regional_center_name,
						u_cpx: datas.midwife_phid,
						u_cpx_EXName: datas.midwife_name,
						u_xs: datas.user_sqgw_phid,
						u_xs_EXName: datas.user_sqgw_name,
						u_hkfzr: datas.project_manager_phid,
						u_hkfzr_EXName: datas.project_manager_name,
						phid_pc: datas.phid_pc,
						phid_pc_EXName: datas.pc_name,
					});
				});
				dgrid1.clearRows().then(() => {
					dgrid1.addRows(_arr);
				});
			}
		);
	}
});